import { useCache } from '@/hooks/useCache'
const { wsCache } = useCache()
// 设置统一登录信息
export const setAllToken = (data) => {
    wsCache.set('allToken', data)
}

export const getAllToken = () => {
    return wsCache.get('allToken')
}

export const setUserInfo = (data) => {
    wsCache.set('userInfo', data)
}

export const getUserInfo = () => {
    return wsCache.get('userInfo')
}

export const setToken = (data) => {
    wsCache.set('token', data)
}

export const getToken = () => {
    return wsCache.get('token')
}

export const setBind = (data) => {
    wsCache.set('Bind', data)
}

export const getBind = () => {
    return wsCache.get('Bind')
}
export const deleteUserCache = () => {
    wsCache.delete('userInfo')
    wsCache.delete('allToken')
    wsCache.delete('token')
    wsCache.delete('Bind')
}

export const clearAllCookies = () => {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
    }
}

export const isPhoneNumber = (phone) => {
    const regex = /^1[3-9]\d{9}$/;
    return regex.test(phone);
}